#include <crtdbg.h>
#include <iostream>
#include "document.h"
#include "primitive.h"
#include "action_common.h"
#include "action_history.h"

using namespace FD;

struct Dummy : public Primitive::Base
{
};

int main()
try
{
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	Document doc;
	Primitive::Base *obj1 = new Dummy();
	Primitive::Base *obj2 = new Dummy();

	Action::History history;
	history.apply( new Action::Create( &doc.m_primitives.m_tail, obj1 ) );
	Position *pos1 = doc.m_primitives.m_tail.prev; // get position by hit test
	history.undo();	// Undo obj1 creating
	history.redo();	// Redo obj1 creating
	history.apply( new Action::Delete( pos1 ) );
	history.undo();	// Undo obj1 deleting
	history.apply( new Action::Create( &doc.m_primitives.m_tail, obj2 ) );
	Position *pos2 = doc.m_primitives.m_tail.prev; // get position by hit test
	history.undo();	// Undo obj2 creating
	history.redo(); // Redo obj2 creating
	//history.redo();	// ASSERT!
}
catch (std::exception &e)
{
	std::cerr << "error: " << e.what() << std::endl;
}